package com.zztl.infiniteBand.receiver

import java.util.*

/**
 *  @desc
 *  @auth ${user}
 *  @time 2019/3/11  11:28
 */
object ContentUtil{
    fun getContentByteList(content:String):List<ByteArray>{
        val list = ArrayList<ByteArray>()
         content?.run {

            val contexts = content.toByteArray(charset("UnicodeBigUnmarked"))//string转unicode编码 大端在前
//             val contexts = HexUtil.hexStringToBytes(HexUtil.str2HexStr(this))
            var index = 0
            while (contexts.size > index) {
                var cmdLength = contexts.size - index//得到剩余数量
                cmdLength = if (cmdLength >= 16) 16 else cmdLength//大于16字节取16字节
                val sms = ByteArray(16)
                System.arraycopy(contexts, index, sms, 0, cmdLength)//copy一包数据
                list.add(sms)
                index += 16
            }
        }
        return list
    }
}